package KK.View
{
	import KK.Data.GameData;
	import KK.EMVC.View.IView;
	import KK.EMVC.View.View;
	import KK.Event.ModuleEvent;
	import KK.GameBase.IMessageQueue;
	import KK.Manager.IManager;
	import KK.Register.View.VRegister;
	import KK.Scene.SceneWord;
	
	public class UIManager extends View implements IManager
	{
		private var ViewVector:Vector.<View>;
		public function UIManager()
		{
			//TODO: implement function
			super();
			init();
		}
		
		/**
		 * 鍒濆鍖?
		 */
		private function init():void{
			
			GameData.Word.addChild(GetMC());
			ViewVector=new Vector.<View>();
		}
		
		
		override public function BindEvent(_event:IMessageQueue):Boolean{
			var result:Boolean=super.BindEvent(_event);
			initEvent();
			return result;
		}
		
		
		/**
		 * 鍚姩
		 */
		public function Run():void{
			
			RegisterView(VRegister);
			RegisterView(SceneWord);
		}
		
		/**
		 * 鍋滄
		 */
		public function Stop():void{
			
		}
		
		
		
		/**
		 * 鍒濆鍖?
		 */
		private function initEvent():void{
			AttentionMessage(ModuleEvent.SHOW,onModuleShow);
			AttentionMessage(ModuleEvent.HIDE,onModuleHide);
		}
		
		/**
		 * 妯″潡闅愯棌
		 * 
		 * @param event    event
		 */
		private function onModuleHide(event:ModuleEvent):void{
			try{
				ViewVector[event.ID].Hide();
			}catch(e:*){
				LogError("隐藏模块出错 。 ",e);
			}
		}
		
		/**
		 * 妯″潡鏄剧ず
		 * 
		 * @param event    event
		 */
		private function onModuleShow(event:ModuleEvent):void{
			ViewVector[event.ID].Show();/*
			try{
				ViewVector[event.ID].Show();
				
			}catch(e:*){
				LogError("隐藏模块出错 。 ",e);
			}
			*/
		}
		
		
		/**
		 * 娉ㄥ唽鏄剧ず绫?
		 * 
		 * @param view    view
		 */
		private function RegisterView(view:Class):void{
			var obj:IView=new view(ViewVector.length);
			
			addView(obj);
			obj.Hide();
			ViewVector.push(obj);
			
		}
	}
}